﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;

namespace Fast
{
    /// <summary>
    /// 枚举扩展方法
    /// </summary>
    [SkipScan]
    public static class EnumExtensions
    {
        /// <summary>
        /// 获取枚举描述
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string GetDescription(this Enum value)
        {
            return value.GetType()?.GetMember(value.ToString())?.FirstOrDefault()?.GetCustomAttribute<DescriptionAttribute>(false)?.Description;
        }
    }
}
